﻿using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace PlantsVsZombies
{
    internal class LoadBar2D : LoadBar
    {
        #region Methods
        public LoadBar2D(Vector2 loadBarPostion)
            : base(loadBarPostion)
        {
        }

        public void LoadContent(ContentManager content)
        {
            Ground = content.Load<Texture2D>(@"Image\Ground");
            Grass = content.Load<Texture2D>(@"Image\Grass");
            Roll = content.Load<Texture2D>(@"Image\Roll");
        }

        public void Update(GameTime gameTime)
        {
            m_RollPosition = new Vector2(40 + LoadBarPosition.X + m_Progress*360,
                                         50 + LoadBarPosition.Y + Roll.Height*m_Progress*0.5f);
            m_RollRotation = m_Progress*10;
            m_RollScale = 1 - m_Progress;
        }

        public void Draw(SpriteBatch spriteBatch)
        {
            //DrawGround
            spriteBatch.Draw(Ground, new Vector2(LoadBarPosition.X, LoadBarPosition.Y + 80), Color.White);
            spriteBatch.Draw(Grass, new Vector2(LoadBarPosition.X, LoadBarPosition.Y + 80),
                             new Rectangle(0, 0, (int) (m_RollPosition.X - LoadBarPosition.X), (Grass.Height)),
                             Color.White, 0, new Vector2(0, 0), new Vector2(1, 0.25f), SpriteEffects.None, 0);

            spriteBatch.Draw(Roll, m_RollPosition, null, Color.White, m_RollRotation,
                             new Vector2(Roll.Width/2, Roll.Height/2), m_RollScale, SpriteEffects.None, 0);
        }
    }

    #endregion
}
